package com.breadenglish.cms.api.app.gateway.manager;


import com.breadenglish.cms.api.app.gateway.anotation.AppPaging;
import com.breadenglish.cms.api.app.gateway.model.WhoBeLike;
import com.breadenglish.cms.api.app.gateway.model.WordOfTheDay;
import com.breadenglish.cms.api.app.gateway.service.WordOfDayService;
import org.jsondoc.core.annotation.*;
import org.jsondoc.core.pojo.ApiStage;
import org.jsondoc.core.pojo.ApiVisibility;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.stream.Collectors;

@Api(name = "每日一词", description = "每日一词资源服务", group = "客户端接口", visibility = ApiVisibility.PUBLIC, stage = ApiStage.RC)
@ApiVersion(since = "1.0", until = "2.12")
@ApiAuthNone
@RestController
@RequestMapping(value = "/wordoftheday")
public class WordOfTheDayController {

    @Resource
    private WordOfDayService wordOfDayService;

    LinkedHashMap<Integer, WordOfTheDay> data = new LinkedHashMap();

    public WordOfTheDayController() {
        int id = 100;
        data.put(id, WordOfTheDay.buildDetails(id--, "今天你被“snubbed”了吗？",
                "不知道什么意思就点进来看看吧~", new Date(), "http://video.breadenglish.com/word_day/img/wdl-pic1.png", "fullSizeImage", null, true, "http://video.breadenglish.com/word_day/pages/page1.html"));
        data.put(id, WordOfTheDay.buildDetails(id--, "在游戏里提刀打怪升级，你得用这个技能！",
                "埃辛诺斯之刃or青龙偃月刀？",
                new Date(), "http://video.breadenglish.com/word_day/img/wdl-pic2.jpg", "fullSizeImage", null, true, "http://video.breadenglish.com/word_day/pages/page2.html"));
        data.put(id, WordOfTheDay.buildDetails(id--, "哇哦，你今天闻起来好极了！",
                "没有大姨妈那就大姨夫，反正不让你爽！",
                new Date(), "http://video.breadenglish.com/word_day/img/wdl-pic3.png", "fullSizeImage", null, true, "http://video.breadenglish.com/word_day/pages/page3.html"));
        data.put(id, WordOfTheDay.buildDetails(id--, "今天大姨妈驾到，来形容下你的感受吧~",
                "没有大姨妈那就大姨夫，反正不让你爽！",
                new Date(), "http://video.breadenglish.com/word_day/img/wdl-pic4.jpg", "fullSizeImage", null, true, "http://video.breadenglish.com/word_day/pages/page4.html"));
        data.put(id, WordOfTheDay.buildDetails(id--, "那一抹氤氲的色彩永远是你最感性的回忆",
                "这个颜色也可以很性感，嗯，自己YY吧~",
                new Date(), "http://video.breadenglish.com/word_day/img/wdl-pic5.png", "fullSizeImage", null, true, "http://video.breadenglish.com/word_day/pages/page5.html"));
        data.put(id, WordOfTheDay.buildDetails(id--, "我被你迷住了~我被你迷住了~我被你迷住了~",
                "重要的事情说三遍！第四遍你就背过了！",
                new Date(), "http://video.breadenglish.com/word_day/img/wdl-pic6.png", "fullSizeImage", null, true, "http://video.breadenglish.com/word_day/pages/page6.html"));
        data.put(id, WordOfTheDay.buildDetails(id--, "男人们，这个词是你们必须要学还要有的！！",
                "我承认女人也要有，否则会很累……",
                new Date(), "http://video.breadenglish.com/word_day/img/wdl-pic7.png", "fullSizeImage", null, true, "http://video.breadenglish.com/word_day/pages/page7.html"));
        data.put(id, WordOfTheDay.buildDetails(id--, "无论发生什么，面包君都会在你身边伴着你~",
                "看好了，只是陪着你，不是让你啃的！！",
                new Date(), "http://video.breadenglish.com/word_day/img/wdl-pic8.jpg", "fullSizeImage", null, true, "http://video.breadenglish.com/word_day/pages/page8.html"));
        data.put(id, WordOfTheDay.buildDetails(id--, "这个词认识就好了，不要轻易做，否则后果自负！",
                "话说出口之前还是先过过脑子吧~",
                new Date(), "http://video.breadenglish.com/word_day/img/wdl-pic9.png", "fullSizeImage", null, true, "http://video.breadenglish.com/word_day/pages/page9.html"));
        data.put(id, WordOfTheDay.buildDetails(id--, "是不是喜欢我很久了，很想要我？面包君等着你哦~",
                "有时候贪得无厌也是一种美德~",
                new Date(), "http://video.breadenglish.com/word_day/img/wdl-pic10.png", "fullSizeImage", null, true, "http://video.breadenglish.com/word_day/pages/page10.html"));
    }

   /* @ApiMethod
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public
    @ApiResponseObject
    WordOfTheDay getById(@ApiPathParam(description = "根据ID获取每日一词数据") @PathVariable(value = "id") int id) {
        return data.get(id);
    }

    @ApiMethod
    @RequestMapping(method = RequestMethod.GET)
    public
    @ApiResponseObject
    Collection<WordOfTheDay> get(@ApiQueryParam(name = "page", required = false, description = "页号") @RequestParam(required = false, defaultValue = "1") int page, @ApiQueryParam(name = "pageSize", required = false, description = "每页Size") @RequestParam(required = false, defaultValue = "10") int pageSize) {
        int size=10;
        int p = page - 1;
        return data.values().stream()
                .skip(p * size)
                .limit(size)
                .collect(Collectors.toList());
    }*/

    @ApiMethod
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ApiResponseObject
    public WordOfTheDay getById(@ApiPathParam(description = "根据ID获取whobelike数据") @PathVariable(value = "id") int id) throws Throwable {
        return wordOfDayService.queryWordOfTheDayById(Long.valueOf(id));
    }

    @ApiMethod
    @RequestMapping(method = RequestMethod.GET)
    @ApiResponseObject
    @AppPaging
    public List<WordOfTheDay> get(@ApiQueryParam(name = "page", required = false, description = "页号")
                                  @RequestParam(required = false, defaultValue = "1") int page,
                                  @ApiQueryParam(name = "pageSize", required = false, description = "每页Size")
                                  @RequestParam(required = false, defaultValue = "10") int pageSize) throws Throwable {
        List<WordOfTheDay> result = wordOfDayService.queryWordOfTheDay();
        return result;
    }
}